// Copyright (c) 2019 Presto Labs Pte. Ltd.
// Author: jaewon

#include "coin1/fastfeed/price_map.h"

#include <vector>

#include <gtest/gtest.h>

namespace fastfeed {

TEST(INT64_PRICE_MAP, ASK_BASICS) {
  AskInt64PriceMap<int> ask_book;
  EXPECT_TRUE(ask_book.empty());

  for (int i = 4; i >= 0; --i) {
    ask_book.SetLevel(i * 5, i * 50);
  }

  std::vector<int> values;
  for (auto v : ask_book) {
    values.push_back(v.second);
  }
  EXPECT_EQ(values, std::vector<int>({0, 50, 100, 150, 200}));

  EXPECT_FALSE(ask_book.GetLevel(1));
  EXPECT_EQ(*ask_book.GetLevel(5), 50);
  EXPECT_EQ(*ask_book.GetLevel(-1, true), 0);
  EXPECT_EQ(*ask_book.GetLevel(12, true), 150);
  EXPECT_FALSE(ask_book.GetLevel(21, true));
}

TEST(INT64_PRICE_MAP, BID_BASICS) {
  BidInt64PriceMap<int> bid_book;
  EXPECT_TRUE(bid_book.empty());

  for (int i = 0; i < 5; ++i) {
    bid_book.SetLevel(i * 5, i * 50);
  }

  std::vector<int> values;
  for (auto v : bid_book) {
    values.push_back(v.second);
  }
  EXPECT_EQ(values, std::vector<int>({200, 150, 100, 50, 0}));

  EXPECT_FALSE(bid_book.GetLevel(19));
  EXPECT_EQ(*bid_book.GetLevel(15), 150);

  EXPECT_FALSE(bid_book.GetLevel(-1, true));
  EXPECT_EQ(*bid_book.GetLevel(12, true), 100);
  EXPECT_EQ(*bid_book.GetLevel(21, true), 200);
}

}  // namespace fastfeed
